package com.jinmdz.fmis.dao.dao;

import com.jinmdz.fmis.dao.dao.provider.ChargeItemProvider;
import com.jinmdz.fmis.dao.model.charge.ChargeItem;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.ArrayList;

/**
 * 服务项目Dao
 *
 * @author LiCongLu
 * @date 2020-02-13 13:30
 */
public interface ChargeItemDao {
    /**
     * 获取业务服务查看费用
     *
     * @param id 费用主键
     * @return
     * @author LiCongLu
     * @date 2020-02-13 18:49
     */
    @SelectProvider(type = ChargeItemProvider.class, method = "getChargeItemById")
    ChargeItem getChargeItemById(@Param("id") Integer id);

    /**
     * 按照业务编码获取服务项目查看费用
     *
     * @param businessCode     业务编码
     * @param randomCode       随机码
     * @param businessChargeId 业务费用主键
     * @return
     * @author LiCongLu
     * @date 2020-02-13 18:49
     */
    @SelectProvider(type = ChargeItemProvider.class, method = "listChargeItemByRandomCode")
    ArrayList<ChargeItem> listChargeItemByRandomCode(@Param("businessCode") String businessCode, @Param("randomCode") String randomCode, @Param("businessChargeId") Integer businessChargeId);

    /**
     * 批量删除服务项目
     *
     * @param businessCode   业务编码
     * @param ids            服务项目集合
     * @param modifiedUserId 修改帐号
     * @return
     * @author LiCongLu
     * @date 2020-02-14 11:21
     */
    @UpdateProvider(type = ChargeItemProvider.class, method = "deletedForChargeItem")
    void deletedForChargeItem(@Param("businessCode") String businessCode, @Param("ids") ArrayList<Integer> ids, @Param("modifiedUserId") Integer modifiedUserId);

    /**
     * 按照业务编码获取服务项目查看费用
     *
     * @param businessCode 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-16 17:13
     */
    @SelectProvider(type = ChargeItemProvider.class, method = "listChargeItemByBusinessCode")
    ArrayList<ChargeItem> listChargeItemByBusinessCode(@Param("businessCode") String businessCode);

    /**
     * 按照业务编码和主键查询服务项目费用
     *
     * @param businessCode
     * @param ids          服务项目集合
     * @return
     * @author LiCongLu
     * @date 2020-02-19 15:32
     */
    @SelectProvider(type = ChargeItemProvider.class, method = "listChargeItemByIds")
    ArrayList<ChargeItem> listChargeItemByIds(@Param("businessCode") String businessCode, @Param("ids") ArrayList<Integer> ids);

    /**
     * 撤销结算状态
     *
     * @param businessCode   业务编码
     * @param chargeSettleId charge_settle主键
     * @param modifiedUserId 修改用户外键
     * @return
     * @author LiCongLu
     * @date 2020-02-20 13:31
     */
    @Update(" update charge_item set as_settled = 0,charge_settle_id = NULL,modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) where business_code = #{businessCode} and charge_settle_id = #{chargeSettleId} and unmodified = 0 and deleted = 0 ")
    void updateForCancellationSettlement(@Param("businessCode") String businessCode, @Param("chargeSettleId") Integer chargeSettleId, @Param("modifiedUserId") Integer modifiedUserId);

    /**
     * 根据业务编码，查询惠民金额
     *
     * @param businessCode 业务编码
     * @return
     * @author GuanKui
     * @date 2020/2/26  14:11
     */
    @Select(" select sum(benefit_charge)  from charge_item where business_code = #{businessCode} and deleted = 0 ")
    @ResultType(BigDecimal.class)
    BigDecimal sumHuiMinReductionByBusinessCode(@Param("businessCode") String businessCode);

    /**
     * 根据charge_settle的ID集合查询费用项目列表数据
     *
     * @param businessCode 业务编码
     * @param settleIds    结算费用主键
     * @return
     * @author ZhangLiRui
     * @date 2020/4/16 16:56
     */
    @SelectProvider(type = ChargeItemProvider.class, method = "listChargeItemBySettleIds")
    ArrayList<ChargeItem> listChargeItemBySettleIds(@Param("businessCode") String businessCode, @Param("settleIds") ArrayList<Integer> settleIds);

    /**
     * 更新退费时的结算主键
     *
     * @param businessCode   业务编码
     * @param chargeSettleId 新结算主键
     * @param refundMinusId  负费用主键
     * @param refundNewId    新费用主键
     * @param modifiedUserId 修改人主键
     * @return
     * @author LiCongLu
     * @date 2020-05-13 11:05
     */
    @Update(" update charge_item set as_settled = 1,charge_settle_id = #{chargeSettleId},modified_user_id = #{modifiedUserId},version = unix_timestamp(now())" +
            " where business_code = #{businessCode} and ( id = #{refundMinusId} or id = #{refundNewId}) and unmodified = 0 and deleted = 0 ")
    void updateForSettleRefund(@Param("businessCode") String businessCode, @Param("chargeSettleId") Integer chargeSettleId, @Param("refundMinusId") Integer refundMinusId, @Param("refundNewId") Integer refundNewId, @Param("modifiedUserId") Integer modifiedUserId);
}